/**
 * Created by wangchun on 15/9/16.
 */
define(function (require, exports, module) {
    var appConstant=require("js/appConstant");//常量配置
    var global=require("js/global");//加载全局js
    var app = angular.module('indexApp', ['ui.router','ngSea','ui.bootstrap','pascalprecht.translate',
        'ngCookies','app.directives','app.filters','app.services','app.components']);
    app.config(['$stateProvider', '$urlRouterProvider', '$controllerProvider', '$compileProvider', '$filterProvider', '$provide',
            function ($stateProvider,   $urlRouterProvider,   $controllerProvider,   $compileProvider,   $filterProvider,   $provide) {

                app.controller = $controllerProvider.register;
                app.directive = $compileProvider.directive;
                app.filter = $filterProvider.register;
                app.factory = $provide.factory;
                app.service = $provide.service;
                app.constant = $provide.constant;
                app.value = $provide.value;
                //配置模块链接路径：中文名、链接名、图标地址、链接地址、控制器名、模版url、控制器url
                //链接名：app作为根项目路径，app.module.name
                //如何将这些路径放到配置文件中来读取
                //首页地址读取配置 链接配置，通过AJAX读取这些配置

                $urlRouterProvider.otherwise('/moduleList');
                $stateProvider
                    .state('moduleList', {
                        url: '/moduleList',
                        views: {
                            "": {
                                controller: 'configModuleListCtrl',
                                cache: 'false',
                                templateUrl: function ($routeParams) {
                                    var url = G.path.moduleTemplatePath + '/module.html';
                                    return global.reg(url);
                                },
                                controllerUrl: G.path.moduleResPath + '/module/list.js'
                            }
                        }
                    })
                    .state('moduleEdit', {
                        url: '/moduleEdit?id',
                        views: {
                            "": {
                                controller: 'configModuleEditCtrl',
                                templateUrl: function ($routeParams) {
                                    return G.path.moduleTemplatePath + '/module/edit.html?id=' + $routeParams.id;
                                },
                                controllerUrl: G.path.moduleResPath + '/module/edit.js'
                            }
                        }
                    })
                    .state('moduleAdd', {
                        url: '/moduleAdd?id',
                        views: {
                            "": {
                                controller: 'configModuleEditCtrl',
                                templateUrl: function ($routeParams) {
                                    return G.path.moduleTemplatePath + '/module/add.html';
                                },
                                controllerUrl: G.path.moduleResPath + '/module/edit.js'
                            }
                        }
                    })

                    .state('moduleLook', {
                        url: '/moduleLook?id',
                        views: {
                            "": {
                                controller: 'configModuleLookCtrl',
                                templateUrl: function ($routeParams) {
                                    return G.path.moduleTemplatePath + '/module/look.html?id=' + $routeParams.id;
                                },
                                controllerUrl: G.path.moduleResPath + '/module/look.js'
                            }
                        }
                    }).state('tableList', {
                        url: '/tableList?module',
                        views: {
                            "": {
                                controller: 'configTableListCtrl',
                                templateUrl: function ($routeParams) {
                                    return G.path.moduleTemplatePath + '/table.html?module=' + $routeParams.module;
                                },
                                controllerUrl: G.path.moduleResPath + '/table/list.js'
                            }
                        }
                    }).state('tableAdd', {
                        url: '/tableAdd?module',
                        views: {
                            "": {
                                controller: 'configTableEditCtrl',
                                templateUrl: function ($routeParams) {
                                    return G.path.moduleTemplatePath + '/table/add.html?module=' + $routeParams.module;
                                },
                                controllerUrl: G.path.moduleResPath + '/table/edit.js'
                            }
                        }
                    }).state('tableEdit', {
                        url: '/tableEdit?module&name',
                        views: {
                            "": {
                                controller: 'configTableEditCtrl',
                                templateUrl: function ($routeParams) {
                                    return G.path.moduleTemplatePath + '/table/edit.html?module=' + $routeParams.module+'&name='+$routeParams.name;
                                },
                                controllerUrl: G.path.moduleResPath + '/table/edit.js'
                            }
                        }
                    }).state('tableLook', {
                        url: '/tableLook?module&name',
                        views: {
                            "": {
                                controller: 'configTableLookCtrl',
                                templateUrl: function ($routeParams) {
                                    return G.path.moduleTemplatePath + '/table/look.html?module=' + $routeParams.module+'&name='+$routeParams.name;
                                },
                                controllerUrl: G.path.moduleResPath + '/table/look.js'
                            }
                        }
                    });
            }]);
    appConstant(app);
    app.run(function ($rootScope, $ngSea) {
        $ngSea(app,{
            route_start:'$stateChangeStart',
            mod_root:G.path.modulePath
        });
    });

    module.exports = app;

});
